package main

import "fmt"

func main()  {
	var arr = []int{2,3,-2,4}
	fmt.Println(maxchengji(arr))
}

func maxa(a,b int) int {
	if a > b {
		return a
	}
	return b
}

func minb(a,b int) int {
	if a > b {
		return b
	}
	return a
}

func maxchengji(arr []int)  int {

	maxhu,minhu := arr[0],arr[0]
	ret := maxhu
	for i :=1;i < len(arr)-1;i++ {
		cur := arr[i]
		if cur > 0 {
			maxhu = maxa(maxhu*cur,cur)
			minhu = minb(minhu*cur,cur)
		}else {
			aa := maxhu
			maxhu = maxa(minhu*cur,cur)
			minhu = minb(aa*maxhu,cur)
		}
		ret = maxa(ret,maxhu)
	}

	return ret
}
